import sys
file = sys.stdout
file.write("hello")

with open('file.txt', mode='r') as f:
    print(f.read(2))   						# 读取两个字节的数据
    print(f.read())



with open('file.txt', mode='r', encoding='utf-8') as f:
    print(f.readline())
    print(f.readline())



with open('file.txt', mode='r', encoding='utf-8') as f:
    print(f.readlines())


string = "Here we are all, by day; by night."		# 字符串
with open('write_file.txt', mode='w', encoding='utf-8') as f:
    size = f.write(string)					# 写入字符串
    print(size)


with open('file.txt') as f:
    print(f.tell())					# 获取文件读写位置
    print(f.read(5))				# 利用read()方法移动文件读写位置
    print(f.tell())

with open('file.txt') as f:
    f.seek(5,0)								# 相对文件开头移动5字节
    f.seek(3,1)


with open('file.txt','rb') as f:
    f.seek(5,0)
    f.seek(3,1)

